<style>
    .twoDiv{
        padding: 10px 0px;
        border-bottom: 1px solid #f6f6f6;
        color: #333;
        height: 160px;
    }
    .three{
        height: 500px;
        padding: 10px 0px;
    }
</style>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-header">费率管理</div>

                        <div class="layui-card-body">
                            <div class="three" >
                                <table class="layui-hide" id="price" lay-filter="price"></table>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button type="button" id="addinformation" class="layui-btn layui-btn-sm">增加信息</button>
        <button type="button" id="modifyinformation" class="layui-btn layui-btn-sm">修改信息</button>
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use(['table', 'form', 'jquery', 'layer', 'tree','util'], function () {
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,table = layui.table;
        var $ = layui.jquery;

        table.render({
            elem: '#price'
            ,url:'../../queryprice'
            ,toolbar: '#toolbarDemo'
            ,hegint: 500
            ,title: '用户数据表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'priceId', title:'ID', width:180, sort: true}
                ,{field:'pickupcharge', title:'提货费', width:180}
                ,{field:'deliveryexpense', title:'送货费', width:180}
                ,{field:'premium', title:'保费', width:180}
                ,{field:'landingcharges', title:'卸货费', width:180}
                ,{field:'initiatemode', title:'是否启用', width:180}
                ,{field:'remark', title:'备注', width:180}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:180}
            ]]
            ,page: true
        });
        //监听行工具事件
        table.on('tool(price)',function (obj) {
            switch (obj.event) {
                case 'del':
                    var priceId=obj.data.priceId;
                    priceDelectDate(priceId);
                    break;
                default:
                    break;
            }
        })

        /*新增跟踪按钮监听点击事件*/
        $("#addinformation").on("click",function(){
            layui.use('layer', function(){
                var layer = layui.layer;
                layer.open({
                    skin:'layui-layer-molv',//皮肤
                    content: '测试回调',
                    //大小
                    area:['70%', '550px'],
                    btn: [],
                    content: '<iframe src="/src/views/rateManagement/iframe/informationadd.html" id="informat" width="100%" height="100%" frameborder="0"/>',
                    closeBtn: 2, //关闭按钮样式默认1
                    anim:4 //设置关闭动画
                });
            });
            return false;
        });

        //日期初始化
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        <!--监听修改-->
        $("#modifyinformation").on("click",function(){
            var table = layui.table;
            var checkStatus = table.checkStatus('price');
            var ids="";
            for(var i=0; i<checkStatus.data.length; i++){
                ids += checkStatus.data[i].priceId;
                if(i !=checkStatus.data.length-1){
                    ids += ",";
                }
            }
            priceUpdateDate(ids);
        });
        <!--修改信息方法-->
        function priceUpdateDate(ids) {
            layui.use(['table','jquery','form'], function(){
                var form = layui.form;
                var table = layui.table;
                var $ = layui.jquery;
                $.ajax({
                    url : '../../getPrice',
                    method : 'post',
                    data :{
                        priceId:ids
                    } ,
                    dataType:"json",
                    success:function(data) {
                        updatepricepopup();
                        setTimeout(function () {
                            //jquery获取内嵌框架对象
                            var modify = $("#modify").contents();
                            modify.find("#priceId").val(data.priceId);
                            modify.find("#pickupcharge").val(data.pickupcharge);
                            modify.find("#deliveryexpense").val(data.deliveryexpense);
                            modify.find("#premium").val(data.premium);
                            modify.find("#landingcharges").val(data.landingcharges);
                            modify.find("#initiatemode").val(data.initiatemode);
                            modify.find("#remark").val(data.remark);
                        }, 500);
                    }
                });
            });
        }

        /*删除信息*/
        //priceId 主键id
        function priceDelectDate(priceid) {
            layui.use(['layer','table','jquery'], function(){
                var layer = layui.layer;
                var table = layui.table;
                var $ = layui.jquery;
                layer.open({
                    content: '测试回调',
                    //大小
                    area:['300px', '180px'],
                    btn: ['确定','取消'],
                    content: '确定要删除?',
                    yes: function(index,kskks){
                        $.ajax({
                            url:'../../delectprice',
                            type:'post',
                            dataType:'text',
                            data:{
                                priceId:priceid
                            },
                            success:function(data){
                                //表刷新方法
                                alert(data);
                                reloads();
                            }
                        });
                        layer.close(index);
                    }
                });
            });
        }
        /*弹出层修改价位*/
        function updatepricepopup(){
            alert("执行");
            layui.use('layer', function(){
                var layer = layui.layer;
                layer.open({
                    skin:'layui-layer-molv',//皮肤
                    content: '测试回调',
                    //大小
                    area:['70%', '550px'],
                    btn: [],
                    content: '<iframe src="/src/views/rateManagement/iframe/modifyprice.html" id="modify" width="100%" height="100%" frameborder="0"/>',
                    closeBtn: 2, //关闭按钮样式默认1
                    anim:4 //设置关闭动画
                });
            });
        }
        /* 表刷新方法 */
        function reloads(){
            layui.use('layer', function(){
                var table = layui.table;
                table.reload("price");
            });
        }
    });
</script>


